home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: uu4news.netcom.com!zodiac!szh
- From: szh@zcon.com (Syed Zaeem Hosain)
- Subject: Re: Q about the float point format......
- Message-ID: <1996Mar19.180521.24842@zcon.com>
- Sender: szh@zcon.com (Syed Zaeem Hosain)
- Nntp-Posting-Host: zodiac
- Reply-To: szh@zcon.com
- Organization: Z Consulting Group
- References: <s3032089.15.314E68DD@sparc13.ncu.edu.tw>
- Date: Tue, 19 Mar 1996 18:05:21 GMT
-
- In article <s3032089.15.314E68DD@sparc13.ncu.edu.tw>, s3032089@sparc13.ncu.edu.tw (Alexander PeaceLand) writes:
- >
- > Could I dynamicly set the digits after the float POINT?
- >
- > In other word... I use printf to print the float point number
- > like 123.456789 but in the other time i only
- > want to print 123.456 or 123.4
- > How shall I do? Thanks! :)
-
- This information should be available in your compiler and run-time
- library reference manuals - look for printf format string descriptions.
- Basically, you need to put some information in the format strings. See
- the following as an example:
-
- zodiac{137}szh: cat foo.c
- #include <stdio.h>
-
- int main ( void )
- {
- double d = 123.456789;
-
- printf ( "%.6f\n" , d );
- printf ( "%.3f\n" , d );
- printf ( "%.1f\n" , d );
- return ( 0 );
- }
- zodiac{138}szh: gcc -o foo foo.c
- zodiac{139}szh: foo
- 123.456789
- 123.457
- 123.5
- zodiac{140}szh:
-
-
- --
- -------------------------------------------------------------------------
- | Syed Zaeem Hosain P. O. Box 610097 (408) 441-7021 |
- | Z Consulting Group San Jose, CA 95161 szh@zcon.com |
- -------------------------------------------------------------------------
-